package demo.restful2;

import javax.ws.rs.*;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: jinshengyuan
 * Date: 2019-02-22
 * Time: 14:47
 * description:
 **/
public class RoomService {
    @GET
    @Path("/room/{id}")
    @Consumes("application/xml")
    public Room getRoom(@PathParam("id")String id )
    {
        System.out.println("get room by id= "+id);
        Room room=RoomDao.getRoom(id);
        return room;
    }
    @GET
    @Path("/room")
    @Consumes("application/xml")
    public Map<String,Room> getAllRoom()
    {
        System.out.println("get all room");
        Map<String,Room> rooms=RoomDao.getRooms();
        return rooms;
    }

    @POST
    @Path("/room")
    @Consumes("application/xml")
    public void addRoom(Room room)
    {
        System.out.println("add room which id is:"+room.getId());
        RoomDao.addRoom(room);
    }
    @PUT
    @Path("/room/{id}")
    @Consumes("application/xml")
    public void updateRoom(@PathParam("id")String id,Room room)
    {
        System.out.println("update room which original id is:"+room.getId());
        RoomDao.updateRoom(id,room);
    }
    @DELETE
    @Path("/room/{id}")
    @Consumes("application/xml")
    public void deleteRoom(@PathParam("id")String id)
    {
        System.out.println("remove room by id= "+id);
        RoomDao.deleteRoom(id);
    }
    @POST
    @Path("/room/{id}")
    @Consumes("application/xml")
    public void addPerson(@PathParam("id") String id,Person person)
    {
        System.out.println("add person who's name is:"+person.getName());
        RoomDao.addPerson(id, person);
    }
    @DELETE
    @Path("/room/{id}/{name}")
    @Consumes("application/xml")
    public void deletePerson(@PathParam("id")String id,@PathParam("name")String name)
    {
        System.out.println("remove person who's name is: "+name);
        RoomDao.deletePerson(id, name);
    }
}
